<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增漫画名称 ')" />
    <!--图片预览css-->
    <th:block th:include="include :: jasny-bootstrap-css" />
    <!--select 下拉框-->
    <th:block th:include="include :: select2-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-name-add">

            <div class="col-sm-12">

                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">漫画名称：</label>
                        <div class="col-sm-8">
                            <input name="name" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>

                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">漫画类型：</label>
                        <div class="col-sm-8">
                            <select name="typeName" class="form-control">
                                <option value=" "> </option>
                                <option th:each="dict : ${@dict.getType('manhua')}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictCode+','+dict.dictLabel}"></option>
                            </select>

                        </div>
                    </div>
                </div>

                <!--
                <div class="form-group">
                <label class="col-sm-3 control-label">漫画类型名称：</label>
                <div class="col-sm-8">
                    <input name="typeName" class="form-control" type="text">
                </div>
                </div>
                -->

            </div>

            <div class="col-sm-12">

                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">最新篇章：</label>
                        <div class="col-sm-8">
                            <input name="newZhang" class="form-control" type="text">
                        </div>
                    </div>
                </div>

                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">漫画作者：</label>
                        <div class="col-sm-8">
                            <input name="author" class="form-control" type="text">
                        </div>
                    </div>
                </div>

            </div>

            <div class="col-sm-12">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">漫画国家：</label>
                        <div class="col-sm-8">
                            <select name="countriesName" class="form-control">
                                <option value=" "> </option>
                                <option th:each="dict : ${@dict.getType('guojia')}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictCode+','+dict.dictLabel}"></option>
                            </select>

                        </div>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
           <hr>
            <div class="form-group" style="margin-left: 15%;">
                <label class="font-noraml">添加封面</label>
                <br/>
                <div class="fileinput fileinput-new" data-provides="fileinput">
                    <div class="fileinput-new thumbnail" style="width: 140px; height: 140px;">
                        <img th:src="@{/img/profile.jpg}">
                    </div>
                    <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"></div>
                    <div>
                        <span class="btn btn-white btn-file"><span class="fileinput-new">选择图片</span><span class="fileinput-exists">更改</span><input type="file" name="theCover" id="theCover"></span>
                        <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
                    </div>
                </div>
            </div>



            <!--<div class="form-group">
                <label class="col-sm-3 control-label">删除标志：</label>
                <div class="col-sm-8">
                    <input name="delFlag" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">点赞：</label>
                <div class="col-sm-8">
                    <input name="give" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">收藏：</label>
                <div class="col-sm-8">
                    <input name="collect" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">评论：</label>
                <div class="col-sm-8">
                    <input name="comment" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">喜欢数量：</label>
                <div class="col-sm-8">
                    <input name="fond" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">阅读数量：</label>
                <div class="col-sm-8">
                    <input name="read" class="form-control" type="text">
                </div>
            </div>-->
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <!--图片预览css-->
    <th:block th:include="include :: jasny-bootstrap-js" />
    <!--select 下拉框-->
    <th:block th:include="include :: select2-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "manhua/name";

        let requiredStr = "不能为空";
        $("#form-name-add").validate({
            ignore: [],
            rules: {
                name: {
                    maxlength: 255,
                    required: true,
                    remote: {
                        url: prefix + "/list",
                        type: "post",
                        dataType: "json",
                        data: {
                            "name": function () {
                                return $.common.trim($("input[name='name']").val());
                            }
                        },
                        success: function (data, type) {
                            if(data.rows.length != web_status.SUCCESS){
                                $.modal.alertWarning('漫画名称已存在!');
                            }
                        }
                    }
                },
                typeName: {
                    maxlength: 255,
                    required: true,
                },
                newZhang: {
                    maxlength: 500,
                    required: true
                },
                author: {
                    maxlength: 255,
                    required: true
                },
                remark: {
                    maxlength: 500,
                    required: true
                },
                theCover:{
                    required: true
                }
            },
            messages: {
                name: {
                    maxlength: "最多输入255个字符.",
                    required: requiredStr,
                    remote:"漫画名称已存在",
                },
                typeName: {
                    maxlength: "最多输入255个字符.",
                    required: requiredStr,
                },
                newZhang: {
                    maxlength: "最多输入500个字符.",
                    required: requiredStr
                },
                author: {
                    maxlength: "最多输入255个字符.",
                    required: requiredStr
                },
                remark: {
                    maxlength: "最多输入500个字符.",
                    required: requiredStr
                },
                theCover:{
                    required: requiredStr
                }
            },
            focusCleanup: true
        });

        /*提交*/
        function submitHandler() {

            if ($.validate.form()) {

                var forData = new FormData();

                forData.append("theCovers",document.getElementById("theCover").files[0]);
                forData.append("name",$("input[name='name']").val());
                forData.append("typeName",$("select[name='typeName']").val());
                forData.append("countriesName",$("select[name='countriesName']").val());
                forData.append("newZhang",$("input[name='newZhang']").val());
                forData.append("author",$("input[name='author']").val());
                forData.append("remark",$("textarea[name='remark']").val());

                var data = {
                    url:prefix + "/add",
                    type:"post",
                    data: forData,
                    dataType: "json",
                    contentType: false,
                    processData: false,
                    success: function(data) {
                        $.operate.ajaxSuccess(data);
                            $.modal.close();
                            $.table.refresh();

                    },
                    error:function(data) {
                        $.modal.alertError("上传失败");
                    }
                }

                $.ajax(data);
                //$.operate.save(prefix + "/add", $('#form-name-add').serialize());
            }
        }
    </script>
</body>
</html>